import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
const history = createWebHistory();
const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/main",
  },
  {
    path: "/main",
    name: "main",
    redirect: "/main/userManage",
    component: () => import("../views/main/index.vue"),
    beforeEnter: (to, from, next) => {
      if (sessionStorage.getItem("id")) {
        next();
      } else {
        next("/login");
      }
    },
    children: [
      {
        path: "userManage",
        component: () => import("../views/userManage/index.vue"),
      },
      {
        path: "homestayManage",
        component: () => import("../views/homestayManage/index.vue"),
      },
      {
        path: "homeTypeManage",
        component: () => import("../views/homeTypeManage/index.vue"),
      },
      {
        path: "reviewManage",
        component: () => import("../views/reviewManage/index.vue"),
      },
      {
        path: "orderManage",
        component: () => import("../views/orderManage/index.vue"),
      },
      {
        path: "commentManage",
        component: () => import("../views/commentManage/index.vue"),
      },
      {
        path: "QandAManage",
        component: () => import("../views/QandAManage/index.vue"),
      },
      {
        path: "TempManage",
        component: () => import("../views/infoManage/index.vue"),
      },
      {
        path: "infoLog",
        component: () => import("../views/infoManage/infoLog.vue"),
      },
      {
        path: "collectManage",
        component: () => import("../views/collectManage/index.vue"),
      },
      {
        path: "center",
        component: () => import("../views/userCenter/index.vue"),
      },
      {
        path: "visible",
        component: () => import("../views/visibleTable/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    redirect: "/login/userLogin",
    component: () => import("../views/login/index.vue"),
    children: [
      {
        path: "userLogin",
        component: () => import("../views/login/userLogin.vue"),
      },
      {
        path: "phoneLogin",
        component: () => import("../views/login/phoneLogin.vue"),
      },
      {
        path: "emailLogin",
        component: () => import("../views/login/emailLogin.vue"),
      },
      {
        path: "register",
        component: () => import("../views/login/register.vue"),
      },
    ],
  },
];
const router = createRouter({
  history,
  routes,
});
export default router;
